package com.ssamkj.neuro;

import org.neuroph.core.NeuralNetwork;
import org.neuroph.core.Neuron;
import org.neuroph.core.data.DataSet;
import org.neuroph.core.data.DataSetRow;
import org.neuroph.nnet.Perceptron;

/**
 * Hello world!
 * 
 */
public class App {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/**
		 * 시파 이거 못 쓰것네.
		 */
		int inputLayer = 3;
		int outputLayer = 2;
		// create new perceptron network
		NeuralNetwork neuralNetwork = new Perceptron(inputLayer, outputLayer);
		
		// create training set
		DataSet trainingSet = new DataSet(inputLayer, outputLayer);
		
		// add training data to training set (logical OR function)
		trainingSet.addRow(new DataSetRow(new double[] { 0, 0 , 0 }, new double[] { 0,0 }));
		trainingSet.addRow(new DataSetRow(new double[] { 0, 0 , 1 }, new double[] { 0,1 }));
		trainingSet.addRow(new DataSetRow(new double[] { 0, 1 , 0 }, new double[] { 0,1 }));
		trainingSet.addRow(new DataSetRow(new double[] { 0, 1 , 1 }, new double[] { 1,0 }));
		trainingSet.addRow(new DataSetRow(new double[] { 1, 0 , 0 }, new double[] { 1,0 }));
		trainingSet.addRow(new DataSetRow(new double[] { 1, 0 , 1 }, new double[] { 1,0 }));
		trainingSet.addRow(new DataSetRow(new double[] { 1, 1 , 0 }, new double[] { 1,0 }));
		trainingSet.addRow(new DataSetRow(new double[] { 1, 1 , 1 }, new double[] { 1,1 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 0, 0 , 0 }, new double[] { 0 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 0, 0 , 1 }, new double[] { 1 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 0, 1 , 0 }, new double[] { 1 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 0, 1 , 1 }, new double[] { 0 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 1, 0 , 0 }, new double[] { 0 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 1, 0 , 1 }, new double[] { 0 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 1, 1 , 0 }, new double[] { 0 }));
//		trainingSet.addRow(new DataSetRow(new double[] { 1, 1 , 1 }, new double[] { 1 }));
		// learn the training set
		System.out.println("before learn - 언제까지 도는거야??? 미친....");
		
//		neuralNetwork.learn(trainingSet);
		neuralNetwork.learnInNewThread(trainingSet);
		try {
			Thread.sleep(1000*10);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("after learn");
		// save the trained network into file
		// neuralNetwork.save("or_perceptron.nnet");
//		for(Neuron n : neuralNetwork.getOutputNeurons()){
//			System.out.println(n.getNetInput());
//		}
//		
		System.out.println("01");
		neuralNetwork.setInput(new double[]{0,0,1});
		for (double d : neuralNetwork.getOutput()) {
			System.out.println(d);
		}
		System.out.println("11");
		neuralNetwork.setInput(new double[]{1,1,1});
		for (double d : neuralNetwork.getOutput()) {
			System.out.println(d);
		}
	}

}
